package com.lsh.oms.provider.service.query;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.lsh.atp.api.model.base.ItemDc;
import com.lsh.atp.api.model.hold.HoldDetailQueryResponse;
import com.lsh.base.common.model.CommonResult;
import com.lsh.oms.api.model.base.OmsItemDc;
import com.lsh.oms.api.model.order.FindOrderByAddressCodeDTO;
import com.lsh.oms.api.model.order.MisOrderHeadForPayDTO;
import com.lsh.oms.api.model.order.OrderDetailDTO;
import com.lsh.oms.api.model.order.OrderHeadDTO;
import com.lsh.oms.api.model.other.OrderShippingHeadDto;
import com.lsh.oms.api.service.query.IFindOrderService;
import com.lsh.oms.core.constant.ReturnCode;
import com.lsh.oms.core.enums.OrderStatus;
import com.lsh.oms.core.enums.PayStatus;
import com.lsh.oms.core.enums.UserType;
import com.lsh.oms.core.exception.BusinessException;
import com.lsh.oms.core.exception.ExceptionStatus;
import com.lsh.oms.core.model.order.OrderDetail;
import com.lsh.oms.core.model.order.OrderHead;
import com.lsh.oms.core.model.order.OrderHeadExt;
import com.lsh.oms.core.model.payment.BillPaymentInfo;
import com.lsh.oms.core.proxy.service.AtpProxy;
import com.lsh.oms.core.proxy.service.GoodsServiceProxy;
import com.lsh.oms.core.service.order.OrderQueryService;
import com.lsh.oms.core.service.payment.BillPaymentService;
import com.lsh.oms.core.service.tool.ToolService;
import com.lsh.oms.core.utils.DateUtil;
import com.lsh.oms.provider.service.BaseService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;


/**
 * @author peter
 */
@Service(protocol = "rest")
@Path("order/find")
@Consumes({MediaType.APPLICATION_FORM_URLENCODED, MediaType.MULTIPART_FORM_DATA, MediaType.APPLICATION_JSON})
@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
public class FindOrderRestServiceImpl extends BaseService implements IFindOrderService {

    private Logger logger = LoggerFactory.getLogger(FindOrderRestServiceImpl.class);

    @Autowired
    private OrderQueryService orderQueryService;

    @Autowired
    private AtpProxy atpProxy;

    @Autowired
    private GoodsServiceProxy goodsServiceProxy;

    @Autowired
    private BillPaymentService billPaymentService;

    @Value("${shopUrl}")
    private String shopUrl;

    @Value("${calUrl}")
    private String calUrl;

    @POST
    @Path("getOrder")
    @Override
    public String getOrderInfo(OrderHeadDTO dto) {
        logger.info("[getOrder Request logSign] : {},[param] : {}", ToolService.getLogSign(), JSON.toJSONString(dto));
        CommonResult<List<OrderHeadDTO>> commonResult = new CommonResult<>();
        StopWatch stopWatch = new StopWatch();
        //1 用户id 查询用户信息 及业务处理
//        stopWatch.reset();
        try {
            stopWatch.start();
            Long orderCode = dto.getOrderCode();
            if (orderCode == null) {
                throw new BusinessException(ReturnCode.REQUEST_PARAMS_IS_NULL, "订单号orderCode不能为空");
            }

            OrderHead coreDto = new OrderHead();
            BeanUtils.copyProperties(dto, coreDto);
            List<OrderHead> dtos = orderQueryService.findList(coreDto, true, true);

            if (CollectionUtils.isEmpty(dtos)) {
                throw new BusinessException(ReturnCode.ORDER_IS_NOT_EXIST, "订单信息不存在");
            }
            List<OrderHeadDTO> resp = new ArrayList<>();
            for (OrderHead head : dtos) {
                OrderHeadDTO respDto = new OrderHeadDTO();
                BeanUtils.copyProperties(head, respDto);
                OrderHeadExt orderHeadExt = head.getExtObject();
                if (null != orderHeadExt) {
                    respDto.setRemark(orderHeadExt.getRemarks());
                }

                if (0L != head.getParentOrderCode()) {
                    JSONObject hExtJson = JSON.parseObject(head.getExt());
                    String MisParentOrderNo = hExtJson.getString("MisParentOrderNo");
                    if (StringUtils.isBlank(MisParentOrderNo)) {
                        MisParentOrderNo = "0";
                    }

                    respDto.setMisParentOrderNo(MisParentOrderNo);
                }

                JSONObject ext;
                if (orderHeadExt != null && StringUtils.isNotEmpty(orderHeadExt.getExt())) {
                    ext = JSONObject.parseObject(orderHeadExt.getExt());
                } else {
                    ext = new JSONObject();
                }
                JSONObject omsPayInfo = new JSONObject();
                omsPayInfo.put("pay_type", head.getPayType());
                omsPayInfo.put("pay_status", head.getPayStatus());
                omsPayInfo.put("pay_channel", head.getPayChannel());

                ext.put("oms_pay_info", omsPayInfo);
                respDto.setExt(ext.toJSONString());
                if (null != orderHeadExt) {
                    respDto.setHeadMisInfo(JSON.toJSONString(orderHeadExt));
                }

                List<OrderDetailDTO> details = new ArrayList<>(head.getDetails().size());
                respDto.setDetails(details);
                for (OrderDetail item : head.getDetails()) {
                    OrderDetailDTO detail = new OrderDetailDTO();
                    BeanUtils.copyProperties(item, detail);
                    details.add(detail);
                }

                resp.add(respDto);
            }

            commonResult.setData(resp);
            commonResult.setMessage("success.");
            commonResult.setCode(ReturnCode.REQUEST_SUCCESS);


        } catch (BusinessException e) {
            logger.error("getOrder 异常" + e.getCode(), e);

            commonResult.setMessage(e.getMessage());
            commonResult.setCode(e.getCode());
        } catch (Exception e) {
            commonResult.setMessage("系统繁忙,请稍后再试或联系相关人员");
            commonResult.setCode(ReturnCode.SYS_ERROR);
        }

        stopWatch.stop();
        logger.info("getOrder 信息 耗时【{}】", stopWatch.getTime());

        return JSON.toJSONString(commonResult, ToolService.valueFilter, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero);
    }

    @POST
    @Path("getUserOrderNum")
    @Override
    public CommonResult<Integer> getUserOrderNum(OrderHeadDTO dto) {
        logger.info("Request logSign : " + ToolService.getLogSign());
        CommonResult<Integer> resps = new CommonResult<>();
        if (dto == null) {
            resps.setCode(ReturnCode.REQUEST_PARAMS_IS_NULL);
            resps.setMessage("用户编码为空，请检验。");
        } else {
            OrderHead coreDto = new OrderHead();
            BeanUtils.copyProperties(dto, coreDto);
            resps.setData(this.orderQueryService.count(coreDto));
            resps.setMessage("");
            resps.setCode(ReturnCode.REQUEST_SUCCESS);
        }
        return resps;
    }

    @POST
    @Path("getOrderType")
    @Override
    public CommonResult<Integer> getOrderType(OrderShippingHeadDto dto) {
        CommonResult<Integer> resps = new CommonResult<>();
        Long orderCode = dto.getOrderId();
        if (orderCode == null) {
            resps.setCode(ReturnCode.REQUEST_FAIL);
            resps.setMessage("订单号不能为空");
            return resps;
        }
        OrderHead oh = orderQueryService.findByCode(orderCode, false, false);
        if (oh == null) {
            resps.setCode(ReturnCode.REQUEST_FAIL);
            resps.setMessage("订单号不存在");
            return resps;
        }
        resps.setCode(ReturnCode.REQUEST_SUCCESS);
        resps.setData(oh.getOrderType());
        return resps;
    }

    /**
     * 查询订单详情信息!
     * 内部逻辑:
     * 该接口，不做"是否支付"的逻辑判断，统一由调用方自己判断
     *
     * @param orderCode
     * @return
     */
    @GET
    @Path("getOrderInfoForRefund")
    @Override
    public String getOrderInfoForRefund(@QueryParam("orderCode") Long orderCode) {
        logger.info("[getOrderInfoForRefund] Request logSign : {},[param] : {}", ToolService.getLogSign(), orderCode);
        CommonResult<OrderHeadDTO> resps = new CommonResult<>();

        try {
            if (orderCode == null) {
                throw new BusinessException(ReturnCode.REQUEST_FAIL, "param is null!!");
            }

            OrderHead head = orderQueryService.findByCode(orderCode, true, true);

            if (head == null) {
                throw new BusinessException(ReturnCode.REQUEST_FAIL, "查询不到orderHead信息, 订单号: " + orderCode);
            }

            List<BillPaymentInfo> billPaymentInfos = billPaymentService.selectList(head.getParentOrderCode()== 0L?head.getOrderCode():head.getParentOrderCode());

            // 判断订单状态,是否是已完成
            if (head.getOrderStatus() != OrderStatus.ORDER_SIGN.getIndex() && head.getOrderStatus() != OrderStatus.ORDER_FINISH.getIndex()) {
                throw new BusinessException(ReturnCode.REQUEST_FAIL, "订单状态不正确, 订单状态:" + OrderStatus.getName(head.getOrderStatus()) + " 订单号: " + orderCode);
            }
            // 判断订单的支付类型,是否是在线支付

            OrderHeadDTO respDto = new OrderHeadDTO();
            BeanUtils.copyProperties(head, respDto);

            List<MisOrderHeadForPayDTO> paySequences = new ArrayList<>(5);
            if(!CollectionUtils.isEmpty(billPaymentInfos)){
                for (BillPaymentInfo billPaymentInfo:billPaymentInfos) {

                    if(billPaymentInfo.getPayStatus().equals(PayStatus.PAID.getValue())){

                        MisOrderHeadForPayDTO misOrderHeadForPayDTO = new MisOrderHeadForPayDTO();
                        BeanUtils.copyProperties(billPaymentInfo, misOrderHeadForPayDTO);

                        paySequences.add(misOrderHeadForPayDTO);
                    }
                }
            }

            respDto.setPaySequences(paySequences);

            OrderHeadExt orderHeadExt = head.getExtObject();
            if (orderHeadExt != null) {
                respDto.setExt(orderHeadExt.getExt());
            }
            List<OrderDetailDTO> details = new ArrayList<>(head.getDetails().size());
            respDto.setDetails(details);
            for (OrderDetail item : head.getDetails()) {
                OrderDetailDTO detail = new OrderDetailDTO();
                BeanUtils.copyProperties(item, detail);
                details.add(detail);
            }

            resps.setData(respDto);
            resps.setMessage("success.");
            resps.setCode(ReturnCode.REQUEST_SUCCESS);
        } catch (BusinessException e) {
            logger.error("[getOrderInfoForRefund] 业务异常code : " + e.getCode() + ",异常信息: " + e.getMessage(), e);
            resps.setCode(e.getCode());
            resps.setMessage(e.getMessage());
        } catch (Exception e) {
            logger.error("[getOrderInfoForRefund] 异常code : " + ExceptionStatus.E3001001.getCode() + ",异常信息: " + e.getMessage(), e);
            resps.setCode(ExceptionStatus.E3001001.getCode());
            resps.setMessage(ExceptionStatus.E3001001.getMessage());
        }

        return JSON.toJSONString(resps, ToolService.valueFilter, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero);
    }


    @GET
    @Path("getIsBeforeNumber")
    @Override
    public CommonResult<String> getIsBeforeNumber(@QueryParam("orderCode") Long orderCode, @QueryParam("addressCode") Long addressCode, @QueryParam("limit") Integer limit) {
        logger.info("Request logSign : " + ToolService.getLogSign());
        if (orderCode == null || addressCode == null || limit == null) {
            return new CommonResult<>(ReturnCode.REQUEST_PARAMS_IS_NULL, "request params is null!", "");
        }

        try {
            List<Long> orderCodes = orderQueryService.findOrderCodesByAddressCode(addressCode, limit);
            if (orderCodes != null && !orderCodes.isEmpty()) {
                Boolean flag = orderCodes.contains(orderCode);
                return new CommonResult<>(ReturnCode.REQUEST_SUCCESS, "ok", flag + "");
            } else {
                return new CommonResult<>(ReturnCode.REQUEST_SUCCESS, "ok", true + "");
            }

        } catch (Exception ex) {
            return new CommonResult<>(ReturnCode.REQUEST_FAIL, ex.getMessage(), "");
        }
    }

    /**
     * 根据用户地址码,查询当天, 当前用户所下订单中,处于'新创建'(包含)~'已分拣'(不包含)状态的订单(餐馆当日合单的需求)
     *
     * @param addressCode 用户地址码
     * @return 返回参数
     */
    @GET
    @Path("getIntradayOrderByAddressCode")
    @Override
    public String getIntradayOrderByAddressCode(@QueryParam("addressCode") Long addressCode) {
        logger.info("Request param: address_code = {}", addressCode);
        CommonResult commonResult = new CommonResult();
        if (addressCode == null) {
            commonResult.setCode(ReturnCode.REQUEST_PARAMS_IS_NULL);
            commonResult.setMessage("address_code is null!");
            return JSON.toJSONString(commonResult);
        }

        try {
            List<OrderHead> orderHeads = orderQueryService.findListByAddressCodeAndStatusRangeAndTimeRange(addressCode, OrderStatus.ORDER_NEW.getIndex(), OrderStatus.ORDER_SORTING.getIndex(), (int) (DateUtil.getMorning().getTime() / 1000), (int) (DateUtil.getNextMorning().getTime() / 1000));
            logger.info("Response:{}", JSON.toJSONString(orderHeads));

            ArrayList<FindOrderByAddressCodeDTO> list = new ArrayList<>();
            for (OrderHead orderHead : orderHeads) {
                FindOrderByAddressCodeDTO findOrderByAddressCodeDTO = new FindOrderByAddressCodeDTO();
                findOrderByAddressCodeDTO.setExpectPayAmount(orderHead.getExpectPayAmount());
                findOrderByAddressCodeDTO.setOrderCode(orderHead.getOrderCode());
                findOrderByAddressCodeDTO.setGoodsTotalAmount(orderHead.getGoodsTotalAmount());
                list.add(findOrderByAddressCodeDTO);
            }

            commonResult.setCode(ReturnCode.REQUEST_SUCCESS);
            commonResult.setMessage("success");
            commonResult.setData(list);

            return JSON.toJSONString(commonResult);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            commonResult.setCode(ReturnCode.SYS_ERROR);
            commonResult.setMessage(e.getMessage());
            return JSON.toJSONString(commonResult);
        }
    }

    /**
     * 获取订单金额
     *
     * @param orderShippingHeadDto 请求参数
     * @return 金额对象
     */
    @POST
    @Path("getOrderMoney")
    @Override
    @Deprecated
    public CommonResult<Object> getMoney(OrderShippingHeadDto orderShippingHeadDto) {
//        String logSign = ToolService.getLogSign();
        CommonResult<Object> commonResult = new CommonResult<>();
//        try {
//            if (orderShippingHeadDto == null || orderShippingHeadDto.getOrderId() == null) {
//                throw new BusinessException(ReturnCode.REQUEST_FAIL, "参数没有订单号");
//            }
//            logger.info(logSign + "其他系统请求算钱参数" + JsonUtils.obj2Json(orderShippingHeadDto));
//            Long orderCode = orderShippingHeadDto.getOrderId();
//
//            CalResultVo calVo = this.requestCal(orderShippingHeadDto, logSign, this.getVenderId());
//
//            BigDecimal sourceMoney = new BigDecimal(calVo.getHead().getMoney());
//            DecimalFormat df = new DecimalFormat("0.000");
//            BigDecimal[] floorMoneyList = sourceMoney.divideAndRemainder(BigDecimal.ONE);
//            BigDecimal floorMoney = new BigDecimal(df.format(floorMoneyList[1]));
//
//            BigDecimal real_pay_money = sourceMoney.subtract(floorMoney);
//
//            Map<String, Object> respMap = new HashMap<>();
//            int userType = this.getUserType(orderCode);
//            if (userType == UserType.KA.getIndex()) {
//                respMap.put("real_pay_money", BigDecimal.ZERO);
//                respMap.put("money", sourceMoney);
//            } else {
//                respMap.put("real_pay_money", real_pay_money);
//                respMap.put("money", real_pay_money);
//            }
//
//            BigDecimal saled_money = new BigDecimal(calVo.getHead().getDiscounted_money());
//            BigDecimal coupon_money = saled_money.subtract(real_pay_money);
//            respMap.put("total_coupon_money", coupon_money);
//
//            commonResult.setCode(ReturnCode.REQUEST_SUCCESS);
//            commonResult.setData(respMap);
//
//            logger.info(logSign + "_" + orderCode + "-getMoney is " + respMap);
//        } catch (BusinessException e) {
//            commonResult.setCode(e.getCode());
//            commonResult.setMessage(e.getMessage());
//            logger.error("业务异常code : " + e.getCode() + ",异常信息: " + e.getMessage(), e);
//        } catch (Exception e) {
//            commonResult.setCode(ExceptionStatus.E3001001.getCode());
//            commonResult.setMessage(ExceptionStatus.E3001001.getMessage());
//            logger.error("业务异常code : " + ExceptionStatus.E3001001.getCode(), e);
//        }

        return commonResult;
    }


    /**
     * 调用计算服务
     *
     * @param orderShippingHeadDto 参数
     * @param logSign              日志标识
     * @return 计算服务参数
     */
//    private CalResultVo requestCal(OrderShippingHeadDto orderShippingHeadDto, String logSign, Long venderId) {
//        Long orderCode = orderShippingHeadDto.getOrderId();
//
//        List<OrderDetail> orderDetails = this.orderQueryService.findDetails(orderCode);
//        if (orderShippingHeadDto.getDetails() == null || orderDetails.size() < orderShippingHeadDto.getDetails().size()) {
//            logger.info(logSign + "传入明细数量大于下单数量");
//            throw new BusinessException(ReturnCode.REQUEST_FAIL, "明细数量大于订单明细数量，请核实");
//        }
//        List<Long> goodsCodeList = new ArrayList<>();
//        for (OrderDetail orderDetail : orderDetails) {
//            goodsCodeList.add(orderDetail.getGoodsCode());
//        }
//
//        OrderHead headDto = orderQueryService.findByCode(orderCode, false, false);
//
//        JSONObject extjson = JSON.parseObject(headDto.getExt());
//        String providerId = extjson.getString("providerId");
//        if (StringUtils.isBlank(providerId)) {
//            throw new BusinessException(ReturnCode.REQUEST_FAIL, "订单信息中没有供商信息，请联系相关人员处理");
//        }
//        //请求商品服务
//        Map<String, Good> codeMaps = goodsServiceProxy.requestCode2Goods(headDto.getOrderCode(), headDto.getParentOrderCode(), providerId, headDto.getVenderId(), logSign);
//        if (codeMaps == null) {
//            logger.info(logSign + ",商品服务获取为空,订单号:" + orderCode);
//            throw new BusinessException(ReturnCode.REQUEST_FAIL, "商品服务获取信息为空");
//        }
//        logger.info(logSign + "请求商品服务返回信息" + JsonUtils.obj2Json(codeMaps));
//
//        //请求计算服务
//        for (OrderShippingDetailDto detailDto : orderShippingHeadDto.getDetails()) {
//            Good good = codeMaps.get(detailDto.getCode());
//            if (good == null) {
//                logger.info(logSign + "商品不在此订单中，处理失败，商品码:" + detailDto.getCode());
//                throw new BusinessException(ReturnCode.REQUEST_FAIL, "商品不在此订单中，处理失败");
//            }
//            logger.info(logSign + JsonUtils.obj2Json(good));
//            detailDto.setItemId(good.getSkuCode());
//            detailDto.setSkuId(good.getGoodsCode());
//        }
//        orderShippingHeadDto.setOrderId(orderCode);
//        CalResultVo calVo = ComputeServiceUtils.getCalService4shipping(orderShippingHeadDto, logSign, calUrl, venderId);
//        logger.info(logSign + "请求计算服务返回信息" + JsonUtils.obj2Json(calVo));
//        if (calVo == null || calVo.getHead() == null || calVo.getHead().getMoney() == null) {
//            logger.info(logSign + ",计算服务获取信息为空,订单号:" + orderCode);
//            throw new BusinessException(ReturnCode.REQUEST_FAIL, "计算服务获取信息为空");
//        }
//
//        return calVo;
//    }


    /**
     * 获取用户类型
     *
     * @param orderCode 订单号
     * @return 用户类型
     */
    private int getUserType(Long orderCode) {
        //用户类型：1-普通用户  2-企业用户 3-KA用户
        OrderHead orderHead = orderQueryService.findByCode(orderCode, false, false);
        if (orderHead != null && StringUtils.isNotBlank(orderHead.getAddressInfo())) {
            String addressInfo = orderHead.getAddressInfo();
            JSONObject addressInfoJson = JSON.parseObject(addressInfo);
            String userType = addressInfoJson.getString("user_type");
            if (StringUtils.isNotBlank(userType)) {
                logger.info(orderCode + "_userType is [ " + userType + " ]");
                return Integer.parseInt(userType);
            }
        } else {
            throw new BusinessException(ReturnCode.REQUEST_FAIL, "订单信息不存在");
        }

        return UserType.PERSONAL.getIndex();
    }


    @Override
    @GET
    @Path("getAtpInfo")
    public CommonResult<List<OmsItemDc>> getOrderAtpInfo(@QueryParam("orderCode") Long orderCode) {

        logger.info("[getOrderAtpInfo] Request logSign : {},[param] : {}", ToolService.getLogSign(), orderCode);
        CommonResult<List<OmsItemDc>> resps = new CommonResult<>();

        try {

            if (orderCode == null) {
                throw new BusinessException(ReturnCode.REQUEST_FAIL, "param is null!!");
            }

            OrderHead head = orderQueryService.findByCode(orderCode, false, false);
            if (head == null) {
                throw new BusinessException(ReturnCode.REQUEST_FAIL, "查询不到orderHead信息, 订单号: " + orderCode);
            }

            Long atpCode = head.getOrderCode();
            if (null != head.getParentOrderCode() && head.getParentOrderCode().compareTo(10L) > 0) {
                atpCode = head.getParentOrderCode();
            }

            HoldDetailQueryResponse holdDetailQueryResponse = this.atpProxy.queryRuleQtyMap(atpCode, head);
            List<OmsItemDc> omsItemDcList = new ArrayList<>();
            if (!CollectionUtils.isEmpty(holdDetailQueryResponse.getItems())) {

                for (ItemDc itemDc : holdDetailQueryResponse.getItems()) {
                    OmsItemDc omsItemDc = new OmsItemDc();
                    omsItemDc.setItem_id(itemDc.getItemId());
                    omsItemDc.setMarket_id(itemDc.getSupplyId());
                    omsItemDc.setSupplier_id(itemDc.getSupplyMarket());
                    omsItemDc.setDc(itemDc.getDc());
                    omsItemDc.setQty(itemDc.getQty());

                    omsItemDcList.add(omsItemDc);
                }
            }

            resps.setData(omsItemDcList);
            resps.setMessage("success");
            resps.setCode(ReturnCode.REQUEST_SUCCESS);
        } catch (BusinessException e) {
            logger.error("[getOrderInfoForRefund] 业务异常code : " + e.getCode() + ",异常信息: " + e.getMessage(), e);
            resps.setCode(e.getCode());
            resps.setMessage(e.getMessage());
        } catch (Exception e) {
            logger.error("[getOrderInfoForRefund] 异常code : " + ExceptionStatus.E3001001.getCode() + ",异常信息: " + e.getMessage(), e);
            resps.setCode(ExceptionStatus.E3001001.getCode());
            resps.setMessage(ExceptionStatus.E3001001.getMessage());
        }

        return resps;
    }

    @GET
    @Path("getHeadInfoByUid")
    @Override
    public CommonResult<OrderHeadDTO> getOrderInfoByUid(@QueryParam("uid") Long uid) {
//        logger.info("[getOrder Request logSign] : {},[param] : {}", ToolService.getLogSign(), JSON.toJSONString(dto));
        CommonResult<OrderHeadDTO> commonResult = new CommonResult<>();
        StopWatch stopWatch = new StopWatch();
        //1 用户id 查询用户信息 及业务处理
        try {
            stopWatch.start();
            if (uid == null) {
                throw new BusinessException(ReturnCode.REQUEST_PARAMS_IS_NULL, "订单号orderCode不能为空");
            }

            List<OrderHead> dtos = orderQueryService.findListByUid(uid, 1, false, false);

            if (CollectionUtils.isEmpty(dtos)) {

                commonResult.setMessage("success.");
                commonResult.setCode(ReturnCode.REQUEST_SUCCESS);
                return commonResult;
//                throw new BusinessException(ReturnCode.ORDER_IS_NOT_EXIST, "订单信息不存在");
            }
            OrderHead head = dtos.get(0);
            OrderHeadDTO respDto = new OrderHeadDTO();
            BeanUtils.copyProperties(head, respDto);

            respDto.setDealTime(respDto.getUpdateTime());

            commonResult.setData(respDto);
            commonResult.setMessage("success.");
            commonResult.setCode(ReturnCode.REQUEST_SUCCESS);

        } catch (BusinessException e) {
            logger.error("getOrder 异常" + e.getCode(), e);

            commonResult.setMessage(e.getMessage());
            commonResult.setCode(e.getCode());
        } catch (Exception e) {
            commonResult.setMessage("系统繁忙,请稍后再试或联系相关人员");
            commonResult.setCode(ReturnCode.SYS_ERROR);
        }

        stopWatch.stop();
        logger.info("getOrderInfoByUid 信息 耗时【{}】", stopWatch.getTime());

        return commonResult;
    }

}
